package com.groupbuying.customer.utils;

import com.groupbuying.customer.domain.CustomerDO;
import com.groupbuying.customer.pojo.SessionContext;
import org.apache.shiro.session.Session;

public class LoginAppUserHelper {
	public static final String LOGIN_APP_USER_TOKEN = "login_app_user_token";
	public static final String LOGIN_APP_USER = "Login_App_User";
	
	public static final String LOGIN_APP_STORE_TOKEN = "login_app_store_token";
	public static final String LOGIN_APP_STORE = "Login_App_Store";
	
	public static String getLoginUserToken(String sessionId, String token) {
		try {
			//sessionId和token，需要手机客户端传过来
			Session session = SessionContext.getInstance().getSession(sessionId);
			session.setTimeout(-1);
			return ((String) session.getAttribute(LoginAppUserHelper.LOGIN_APP_USER_TOKEN+token));
		} catch (Exception err) {
			err.printStackTrace();
		}
		return "";
	}
	
	public static CustomerDO getLoginUserModel(String sessionId) {
		try {
			Session session = SessionContext.getInstance().getSession(sessionId);
			CustomerDO customerModel = (CustomerDO)session.getAttribute(LOGIN_APP_USER);
			return customerModel;
		} catch (Exception err) {
			err.printStackTrace();
		}
		return null;
	}
	
	public static String getLoginStoreToken(String sessionId, String token) {
		try {
			//sessionId和token，需要手机客户端传过来
			Session session = SessionContext.getInstance().getSession(sessionId);
			session.setTimeout(-1);
			return ((String) session.getAttribute(LoginAppUserHelper.LOGIN_APP_STORE_TOKEN+token));
		} catch (Exception err) {
			err.printStackTrace();
		}
		return "";
	}

	
}
